package com.taxigang.client.uibinder;

import java.util.Date;

import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.user.client.Command;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.TextBox;
import com.google.gwt.user.client.ui.Widget;
import com.taxigang.client.Session;
import com.taxigang.client.facebook.FacebookApi;
import com.taxigang.client.micro.TaxiGangCreator;
import com.taxigang.client.ui.map.MapView.PanelType;
import com.taxigang.client.uibinder.base.CreateStep;
import com.taxigang.shared.ChitInfo;
import com.taxigang.shared.LoginInfo;
import com.taxigang.shared.TaxiGangInfo;

public class CreateStep4 extends CreateStep {

	private static CreateStep4UiBinder uiBinder = GWT
			.create(CreateStep4UiBinder.class);

	interface CreateStep4UiBinder extends UiBinder<Widget, CreateStep4> {
	}


	@UiField
	Label enterANicknameLabel;

	@UiField Button backButton;
	
	@UiField Button okButton;
	@UiField TextBox nickNameTextBox;
	@UiField
	Label headerLabel;

	public CreateStep4() {
		initWidget(uiBinder.createAndBindUi(this));
		enterANicknameLabel.setText(TaxiGangCreator.taxiGangConstants.enterNickName());
		okButton.setText(TaxiGangCreator.taxiGangConstants.cont());
		headerLabel.setText(TaxiGangCreator.taxiGangConstants.step4());

		okButton.addClickHandler(new ClickHandler() {
			
			@Override
			public void onClick(ClickEvent event) {
				Window.alert("CreateStep4:error");
//				TaxiGangInfo info = Session.getInstance().getSearchTaxiGangInfo();
//				String nickName = nickNameTextBox.getText();
//				if (nickName.trim().length() == 0){
//					nickName = Session.getInstance().getTaxiGangUserInfo().getDisplayName();
//				}
//				String message = TaxiGangCreator.taxiGangConstants.meetingPlace()+":"+info.getMeetingMessage();
//				message += "Mobil:"+Session.getInstance().getLoginInfo().getMobilenumber();
//				ChitInfo chit = new ChitInfo(message, new Date(), nickName);
//				TaxiGangPresenter.getInstance().createWithWait(chit);
			}
		});

		backButton.addClickHandler(new ClickHandler() {
			
			@Override
			public void onClick(ClickEvent event) {
				taxiGangRoute.show(PanelType.CREATE_STEP3);								
			}
		});

	}
	
	public void show(){
		final TaxiGangInfo info = Session.getInstance().getSearchTaxiGangInfo();
		LoginInfo loginInfo = Session.getInstance().getLoginInfo();
		String message = info.getMeetingMessage();

		String name = loginInfo.getNickname();
		ChitInfo chit = new ChitInfo(message, new Date(), name, loginInfo.getMobilenumber());
		TaxiGangPresenter.getInstance().createWithWait(chit);

	}

}
